package com.cvit.cn.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cvit.cn.bean.ReleaseInformation;
import com.cvit.cn.dao.ReleaseInformationMapper;
import com.cvit.cn.test.Utils;
import com.cvit.cn.test.UuidUtil;

@Service
public class ReleaseInformationService {
	@Autowired
	ReleaseInformationMapper releaseInformationMapper;
	
	public Date makeDate(String str) throws Exception{
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
		Date date = sdf.parse(str);
		java.sql.Date sqlDate = new java.sql.Date(date.getTime());
		return sqlDate;
	}

	/*
	 * 增加发布信息
	 */
	public int addReleaseInformation(ReleaseInformation addReleaseInformation){
		return releaseInformationMapper.insert(addReleaseInformation);
	}
	
	/*
	 * 删除发布信息
	 */
	public int delReleaseInformation(String[] ids) {
		return releaseInformationMapper.delReleaseInformation(ids);
	}
	
	/*
	 * 查询发布信息
	 */
	public List<ReleaseInformation> selectReleaseInformation() {
		 List<ReleaseInformation> list = releaseInformationMapper.selectReleaseInformation();
		 return list;
	}
	/*
	 * 修改发布信息
	 */
	public int updateReleaseInformation(ReleaseInformation updateReleaseInformation){
		return releaseInformationMapper.updateByPrimaryKey(updateReleaseInformation);
	}
	/*
	 * 修改发布信息ForQuoteType=1
	 */
	public int updateReleaseInformationForQuoteType(){
		return releaseInformationMapper.updateReleaseInformationForQuoteType();
	}
	
	/*
	 * 假删除发布信息
	 */
	public int delReleaseInformationFalse(String[] ids) {
		return releaseInformationMapper.delReleaseInformationFalse(ids);
	}

	/**
	 * 添加标题信息（对的）
	 * */
	public void addRele(ReleaseInformation releaseInformation,String quote_flag) throws ParseException {
		System.out.println(quote_flag);
		// TODO Auto-generated method stub
		String uuid=Utils.getsUUID().toString();
		releaseInformation.setId(uuid);
		releaseInformation.setQuoteFlag(new SimpleDateFormat("yyyy-MM-ddHH:mm:ss").parse(quote_flag));
		releaseInformation.setQuoteType("0");
		releaseInformationMapper.insert(releaseInformation);
	}
	/**
	 * （如果数据库里的时间<=当前时间就赋值quote_type=1）的查询 
	 * */
	public List<ReleaseInformation> getType() {
		// TODO Auto-generated method stub
		return releaseInformationMapper.selectQuoteTypeBy(null);
	}
	/**
	 * 根据quote_type=0查询查询已发布订单
	 * */
	public List<ReleaseInformation> getTypeZero() {
		// TODO Auto-generated method stub
		return releaseInformationMapper.selectQuoteTypeByZero(null);
	}
	/**
	 * 根据quote_type=null查询查询未发布订单
	 * */
	public List<ReleaseInformation> getTypeNull() {
		// TODO Auto-generated method stub
		return releaseInformationMapper.selectQuoteTypeByNull(null);
	}

	public String addRele(String id,String title, String content) throws Exception {
		// TODO Auto-generated method stub
		//String uuid=Utils.getsUUID().toString();
		ReleaseInformation releaseInformation=new ReleaseInformation();
		releaseInformation.setId(id);
		releaseInformation.setTitle(title);
		releaseInformation.setContent(content);
//		releaseInformation.setQuoteStart(new SimpleDateFormat("yyyy-MM-ddHH:mm:ss").parse(quoteStart));
//		releaseInformation.setQuoteFlag(new SimpleDateFormat("yyyy-MM-ddHH:mm:ss").parse(quoteFlag));
		releaseInformation.setQuoteType("0");
		releaseInformationMapper.insert(releaseInformation);
		return id;
	}

	public int updateId(ReleaseInformation ri) {
		// TODO Auto-generated method stub
		return releaseInformationMapper.updateId(ri);
	}

	public List<ReleaseInformation> getTest() {
		// TODO Auto-generated method stub
		return releaseInformationMapper.seleTest(null);
	}

	/***
	 * 根据订单id查开始时间和结束时间
	 * */
	public ReleaseInformation getReleaseIdTime(String id) {
		// TODO Auto-generated method stub
		return releaseInformationMapper.getReleaseIdTime(id);
	}

	public List<ReleaseInformation> getTypeOne() {
		// TODO Auto-generated method stub
		return releaseInformationMapper.selectByExample(null);
	}

	/***
	 * 查未处理状态
	 * */
	public List<ReleaseInformation> getReleaseIdSupplierType() {
		// TODO Auto-generated method stub
		return releaseInformationMapper.getReleaseIdSupplierType(null);
	}
	/***
	 * 查未理状态
	 * */
	public List<ReleaseInformation> getReleaseIdSupplierTypeOne() {
		// TODO Auto-generated method stub
		return releaseInformationMapper.getReleaseIdSupplierTypeOne(null);
	}
	
}
